package gr.atc.epart;

import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

public class GoogleServicesProvider
{

	private class GoogleServicesURLProvider
	{
		public String getGeocoderURL()
		{
			return "http://maps.google.com/maps/geo";
		}
	}
	
	private GoogleServicesURLProvider _urlProvider;
	
	public GoogleServicesProvider()
	{
		_urlProvider = new GoogleServicesURLProvider();
	}
	
	
	//
	// Translate
	//

	//
	// OpenSocial
	//
	
	//
	// MAPS
	//
	
	//
	// Web Albums
	//
	
	//
	// Youtube
	//
	
	
	//
	// Blogger
	//
	

	//
	// Geocoding (maybe not needed, but used for initial development )
	//
	public String geoCode(String address, String language)
	{
		HttpConnector connection= new HttpConnector();

		String geocodeRequest  = createGeocodeRequest(address, language);
		String geocodeResponse = connection.executeGetRequest(geocodeRequest);
		
		return geocodeResponse;
	}

	private String createGeocodeRequest(String address, String language)
	{
		// this request may contain spaces, commas etc and must me URL encoded
		return String.format("%s?output=json&hl=%s&oe=utf-8&q=%s",_urlProvider.getGeocoderURL(),language,Uri.encode(address).toString());
	}
	
	//
	// Reverse Geocoding (maybe not needed)
	//
	
	public String reverseGeocode(double lat, double lon, String language )
	{
		HttpConnector connection= new HttpConnector();

		String reverseGeocodeRequest  = createReverseGeocodeRequest(lat,lon, language);
		String reverseGeocodeResponse = connection.executeGetRequest(reverseGeocodeRequest);
		
		return reverseGeocodeResponse;
	}
	
	private String createReverseGeocodeRequest(double lat, double lon, String language)
	{
		return String.format("%s?output=json&hl=%s&oe=utf-8&ll=%s,%s",_urlProvider.getGeocoderURL(),language,Double.toString(lat),Double.toString(lon) );
	}
}
